package main

import (
	"MaterialIdentification/svc"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Savematerial(context *gin.Context) {
	m := material{}
	context.BindJSON(&m)

	m1 := material{}
	svc.Db.Where("name = ?", m.Name).Find(&m1)

	err := svc.Db.Model(&material{}).Where("name = ?", m.Name).Update("num", m1.Num+m.Num).Error
	if err != nil {
		context.JSON(http.StatusOK, NewResp(1, "数据库异常"))
		return
	}
	err = svc.Db.Model(&material{}).Where("name = ?", m.Name).Update("lasttime", m.Lasttime).Error
	if err != nil {
		context.JSON(http.StatusOK, NewResp(1, "数据库异常"))
		return
	}

	context.JSON(http.StatusOK, NewResp(0, "保存成功"))
}
